package lab.gene.service.impl;

import java.util.Date;
import java.util.List;

import lab.gene.pojo.Gene;
import lab.gene.pojo.GeneColony;
import lab.gene.service.GeneColonyPCRService;
import lab.gene.dao.GeneColonyDAO;
import lab.gene.dao.GeneDAO;
import lab.user.dao.UserDAO;
import lab.user.pojo.User;

public class GeneColonyPCRServiceImpl implements GeneColonyPCRService {

	@Override
	public GeneColony getGeneColonyByTypeAndName(String type, String geneName) {
		// TODO Auto-generated method stub
		GeneColony gcln = null;
		GeneColonyDAO dao = new GeneColonyDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		gcln = dao.getGeneColonyByNameAndType(g, type);
		return gcln;
	}

	@Override
	public void addGeneColony(String geneName, String type, int size, Date date1, Date date2, Date date3, String primer1, String primer2, String primer3, String userName, String pno1, String pno2) {
		UserDAO udao = new UserDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		User u = udao.getUser(userName);
		GeneColonyDAO dao = new GeneColonyDAO(); 
		GeneColony gc= new GeneColony();
		gc.setDate1(date1);
		gc.setDate2(date2);
		gc.setDate3(date3);
		gc.setDateModified(new Date());
		gc.setGene(g);
		gc.setPno1(pno1);
		gc.setPno2(pno2);
		gc.setPrimer1(primer1);
		gc.setPrimer2(primer2);
		gc.setPrimer3(primer3);
		gc.setSize(size);
		gc.setType(type);
		gc.setUser(u);
		dao.addGeneColony(gc);
		// TODO Auto-generated method stub
	}

	@Override
	public List<GeneColony> getGeneColonyHistory(String geneName, String type) {
		List<GeneColony> g = null;
		GeneDAO gdao = new GeneDAO();
		Gene gene = gdao.getGene(geneName);
		GeneColonyDAO dao = new GeneColonyDAO();
		g = dao.getGeneColonyHistory(gene, type);
		return g;
	}

}
